import { createWebHashHistory, createRouter } from 'vue-router';
import routes from './routes';

const router = createRouter({
  history: createWebHashHistory(),
  routes,
  scrollBehavior(_to, _from, savedPosition) {
    return savedPosition
      ? savedPosition
      : {
          left: 0,
          top: 0,
        };
  },
});

router.beforeEach((_to, _from, next) => {
  next();
});

router.afterEach((to) => {
  document.title = (to.meta?.title as string) || 'test';
});
console.log(import.meta.hot,router.getRoutes());
// 仅开发环境触发
if (import.meta.hot) {
  import.meta.hot.send("typed-router:routes", router.getRoutes());
}

export default router;
